using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;

namespace DataEntity
{
    public class T_Project_UnionDeveloper : DBInteractionBase
    {
        #region Class Member Declarations
        private SqlInt32 _project_UnionDeveloper_FirstA1;
        private SqlString _project_UnionDeveloper_FirstA2, _project_UnionDeveloper_FirstA3;
        private SqlGuid _project_UnionDeveloper_ID, _project_UnionDeveloper_MainID;
        #endregion


        public T_Project_UnionDeveloper()
        {
            // Nothing for now.
        }





        public override bool Update()
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Project_UnionDeveloper_Update]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;

            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_UnionDeveloper_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_UnionDeveloper_ID));
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_UnionDeveloper_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_UnionDeveloper_MainID));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_UnionDeveloper_FirstA1", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _project_UnionDeveloper_FirstA1));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_UnionDeveloper_FirstA2", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_UnionDeveloper_FirstA2));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                _rowsAffected = cmdToExecute.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Project_UnionDeveloper::Update::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
            }
        }


        public override bool Delete()
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Project_UnionDeveloper_Delete]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;

            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_UnionDeveloper_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_UnionDeveloper_ID));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                _rowsAffected = cmdToExecute.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Project_UnionDeveloper::Delete::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
            }
        }


        public override DataTable SelectOne()
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Project_UnionDeveloper_SelectOne]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;
            DataTable toReturn = new DataTable("t_Project_UnionDeveloper");
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;

            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_UnionDeveloper_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_UnionDeveloper_ID));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                adapter.Fill(toReturn);
                if (toReturn.Rows.Count > 0)
                {
                    _project_UnionDeveloper_ID = (Guid)toReturn.Rows[0]["Project_UnionDeveloper_ID"];
                    _project_UnionDeveloper_MainID = (Guid)toReturn.Rows[0]["Project_UnionDeveloper_MainID"];
                    _project_UnionDeveloper_FirstA1 = toReturn.Rows[0]["Project_UnionDeveloper_FirstA1"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["Project_UnionDeveloper_FirstA1"];
                    _project_UnionDeveloper_FirstA2 = toReturn.Rows[0]["Project_UnionDeveloper_FirstA2"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_UnionDeveloper_FirstA2"];
                }
                return toReturn;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Project_UnionDeveloper::SelectOne::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
                adapter.Dispose();
            }
        }


        public override DataTable SelectAll()
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Project_UnionDeveloper_SelectAll]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;
            DataTable toReturn = new DataTable("t_Project_UnionDeveloper");
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;

            try
            {

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                adapter.Fill(toReturn);
                return toReturn;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Project_UnionDeveloper::SelectAll::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
                adapter.Dispose();
            }
        }


        #region Class Property Declarations
        public SqlGuid Project_UnionDeveloper_ID
        {
            get
            {
                return _project_UnionDeveloper_ID;
            }
            set
            {
                _project_UnionDeveloper_ID = value;
            }
        }


        public SqlGuid Project_UnionDeveloper_MainID
        {
            get
            {
                return _project_UnionDeveloper_MainID;
            }
            set
            {
                SqlGuid project_UnionDeveloper_MainIDTmp = (SqlGuid)value;
                if (project_UnionDeveloper_MainIDTmp.IsNull)
                {
                    throw new ArgumentOutOfRangeException("Project_UnionDeveloper_MainID", "Project_UnionDeveloper_MainID can't be NULL");
                }
                _project_UnionDeveloper_MainID = value;
            }
        }


        public SqlInt32 Project_UnionDeveloper_FirstA1
        {
            get
            {
                return _project_UnionDeveloper_FirstA1;
            }
            set
            {
                SqlInt32 project_UnionDeveloper_FirstA1Tmp = (SqlInt32)value;
                if (project_UnionDeveloper_FirstA1Tmp.IsNull)
                {
                    throw new ArgumentOutOfRangeException("Project_UnionDeveloper_FirstA1", "Project_UnionDeveloper_FirstA1 can't be NULL");
                }
                _project_UnionDeveloper_FirstA1 = value;
            }
        }


        public SqlString Project_UnionDeveloper_FirstA2
        {
            get
            {
                return _project_UnionDeveloper_FirstA2;
            }
            set
            {
                SqlString project_UnionDeveloper_FirstA2Tmp = (SqlString)value;
                if (project_UnionDeveloper_FirstA2Tmp.IsNull)
                {
                    throw new ArgumentOutOfRangeException("Project_UnionDeveloper_FirstA2", "Project_UnionDeveloper_FirstA2 can't be NULL");
                }
                _project_UnionDeveloper_FirstA2 = value;
            }
        }
        public SqlString Project_UnionDeveloper_FirstA3
        {
            get
            {
                return _project_UnionDeveloper_FirstA3;
            }
            set
            {
                SqlString project_UnionDeveloper_FirstA3Tmp = (SqlString)value;
                if (project_UnionDeveloper_FirstA3Tmp.IsNull)
                {
                    throw new ArgumentOutOfRangeException("Project_UnionDeveloper_FirstA3", "Project_UnionDeveloper_FirstA3 can't be NULL");
                }
                _project_UnionDeveloper_FirstA3 = value;
            }
        }
        #endregion
    }
}
